package com.atguigu.service.impl;

import com.atguigu.base.BaseMapper;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.entity.UserFollow;
import com.atguigu.entity.vo.UserFollowVo;
import com.atguigu.mapper.UserFollowMapper;
import com.atguigu.service.UserFollowService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {

    @Autowired
    private UserFollowMapper userFollowMapper;
    @Override
    public BaseMapper<UserFollow> getBaseMapper() {
        return userFollowMapper;
    }

    @Override
    public UserFollow isFollow(Long userId, Long houseId) {
        return userFollowMapper.isFollow(userId,houseId);
    }

    @Override
    public UserFollow findUserFollowByUserIdAndHouseId(Long userId, Long houseId) {
        return userFollowMapper.findUserFollowByUserIdAndHouseId(userId, houseId);
    }

    @Override
    public PageInfo<UserFollowVo> findUserFollowVoPage(Integer pageNum, Integer pageSize, Long userId) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserFollowVo> list = userFollowMapper.findUserFollowVoPage(userId);
        return new PageInfo<>(list,10);
    }

    @Override
    public void cancelFollowById(Long id) {
        //根据id查询UserFollow
        UserFollow userFollow = userFollowMapper.getById(id);
        //将查询到的数据的IsDeleted设置为1
        userFollow.setIsDeleted(1);
        //将数据更改到表中
        userFollowMapper.update(userFollow);
    }
}
